var s1 = "get-element-by-id";
function f(str){
    let reg = /-([a-zA-Z])/g;
    return str.replace(reg,(match, $1)=>{
        return $1.toUpperCase();
    })
}
// console.log(f(s1))

let s2 = 'sadfdsfadfsa'
function containsNumber(str){
    let reg = /\d/g;
    return reg.test(str)
}
// console.log(containsNumber(s2))

let s3= '222-222-2222'
function matchesPattern(str){
    let reg = /^(\d{3})-\1-\d{4}$/g;
    return reg.test(str)
}
// console.log(matchesPattern(s3))

let s4= '$1,023,032.03'
function isUSD(str){
    let reg = /^\$\d{1,3}(,\d{3})*(\.\d{2})?$/g;
    return reg.test(str)
}
// console.log(isUSD(s4))

let s5= '1234567890'
function format(str){
    let reg = /\d{1,3}(?=(\d{3})+)/g;
    return str.replace(reg, '$&,')
}
// console.log(format(s5))

let s6= 'https://baike.baidu.com?name=zhangsan&age=26&'
function format(url, key){
    let reg = /[\?|\&](\w+)=(\w+)/g;
    let arr = {}; 
    url.replace(reg, (match,matchKey,matchValue)=>{
        if(!arr[matchKey]){
            arr[matchKey] = matchValue;
        } else {
            arr[matchKey] = [].concat(temp, matchValue);
        }
    });
    // console.log(arr)
}
// console.log(format(s6, 'name'))

let s7= '<p>dasdsa</p>nice <br> test</br>'
function tag(str){
    let reg = /(?<=<)(\w)+(?=>)/g;
    return str.match(reg);

}
// console.log(tag(s7, 'name'))

let reg1 = /(?![^A_Z]+)\w{6,}/g

let arr = [1,2,3,4,1,2,2,2];
let result = []
arr.reduce((a,c) => {
  if(a[c]) !result.includes(c) && result.push(c);
  else a[c]=1;
  return a
}, {})
// console.log(result)


function filter(arr){
    let obj = {};
    let result = [];
    arr.forEach(item=>{
        if(obj[item]){
            obj[item] === 1 && result.push(item)
            obj[item]++;
        } else {
            obj[item] = 1;
        }
    })
    return result;
}
// console.log(filter(arr))


function showCase(value) {
    switch(value) {
      case 'A':
        console.log('Case A');
        break;
      case 'B':
        console.log('Case B');
        break;
      case undefined:
        console.log('undefined');
        break;
      default:
        console.log('Do not know!');
    }
  }
//   showCase(new String('A'))


  var name = 'spring';
  (function () {
      if (typeof name === 'undefined') {
        var name = 'summer';
        console.log(name);
      } else {
        console.log(name);
      }
  })();